

package com.hazelcast.map.impl.mapstore.writebehind.entry;

import com.hazelcast.map.EntryLoader.MetadataAwareValue;
import com.hazelcast.map.MapStore;

import java.util.UUID;

/**
 * Represents a candidate entry to be deleted from {@link MapStore}
 *
 * @param <K> the key type.
 * @param <V> the value type.
 */
class DeletedDelayedEntry<K, V> implements DelayedEntry<K, V> {

    private final K key;
    private final int partitionId;
    private long storeTime;
    private volatile long sequence;
    private UUID txnId;

    DeletedDelayedEntry(K key, long storeTime, int partitionId) {
        this.key = key;
        this.storeTime = storeTime;
        this.partitionId = partitionId;
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return null;
    }

    @Override
    public long getExpirationTime() {
        return MetadataAwareValue.NO_TIME_SET;
    }

    @Override
    public long getStoreTime() {
        return storeTime;
    }

    @Override
    public void setStoreTime(long storeTime) {
        this.storeTime = storeTime;
    }

    @Override
    public int getPartitionId() {
        return partitionId;
    }

    @Override
    public long getSequence() {
        return sequence;
    }

    @Override
    public void setSequence(long sequence) {
        this.sequence = sequence;
    }

    @Override
    public UUID getTxnId() {
        return txnId;
    }

    @Override
    public void setTxnId(UUID txnId) {
        this.txnId = txnId;
    }

    /**
     * This method is used when we are cleaning processed instances of this class.
     * Caring only reference equality of objects because wanting exactly remove the same instance
     * otherwise this method should not cause any remove from staging area.
     *
     * @see com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore#removeFromStagingArea
     */
    @Override
    public boolean equals(Object o) {
        return this == o;
    }

    @Override
    public int hashCode() {
        return key.hashCode();
    }

    @Override
    public String toString() {
        return "DeletedDelayedEntry{" + "key=" + key + ", partitionId=" + partitionId + ", storeTime=" + storeTime + ", sequence=" + sequence + ", txnId=" + txnId + '}';
    }
}
